package com.example.sendmassege.scoket;

import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * @author wxc
 * @date 2021年04月30日 11:01
 */
public class TcpClientDemo {
    public static void main(String[] args) {
        try {
            //1.要知道服务器的地址和端口号
            InetAddress serverIP = InetAddress.getByName("127.0.0.1");
            int port = 9999;
            //2.创建一个socket的连接
            Socket socket = new Socket(serverIP, port);
            //3.发送消息IO流
            OutputStream os = socket.getOutputStream();
            os.write("你好欢迎学习狂神说".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
